<template>
  <div>
    <!-- 头部 -->
    <div class="header">
      <!--<div class="goto">-->
      <!--<router-link to="/ratify">-->
      <!--<img src="../../assets/home_img/left.png" alt="">-->
      <!--</router-link>-->
      <!--</div>-->
      <p>绑定手机</p>
    </div>
    <div style="height: 2.4rem"></div>

    <!-- 内容 -->
    <div class="content">
      <p class="annotation">*请根据您微信绑定的手机号进行身份关联</p>
      <input class="iptPhone" type="number" placeholder="请填写手机号" v-model="mobile" oninput="if(value.length>11)value=value.slice(0,11)">
      <!-- 提交 -->
      <div class="okbtn" @click="okbtn()">
        <p>下一步</p>
      </div>
    </div>



    <div class="winshow" v-if="winshow">
      <div class="an"></div>
      <div class="ming">
        <div class="mingtext">
          <p>{{msgtext}}</p>
          <!--<p>{{msgnumber}}</p>-->
        </div>
        <div class="mingbtnbox">
          <div class="mingbtn" @click="winnone()">
            <p>确定</p>
          </div>
        </div>
      </div>
    </div>

    <div class="winshow" v-if="winshow1">
      <div class="an"></div>
      <div class="ming">
        <div class="mingtext">
          <p>{{msgtext}}</p>
          <!--<p>{{msgnumber}}</p>-->
        </div>
        <div class="mingbtnbox">
          <div class="mingbtn" @click="next()">
            <p>确定</p>
          </div>
        </div>
      </div>
    </div>

  </div>
</template>

<script>
  import utils from '../../config/utils'
  export default {
    data() {
      return {
        mobile:'',
        code:'',
        openId:'',


        //  弹框
        winshow:false,
        winshow1: false,
        msgtext:'',
      }
    },
    created(){
      this.verify();
    },
    methods: {
      //  验证
      verify(){
        let code = utils.getUrlKey('code')
        console.log(code);
        let postData = this.$qs.stringify({
          code: code,
        });
        this.$axios({
          method:'POST',
          url:'api/customer/checkWxBind',
          data:postData
        }).then((res)=>{
          console.log(res.data.msg);
          if (res.data.ret == 0){
            this.openId = res.data.data;
          } else {
            this.$router.replace({
              path:'/order'
            });
          }

        }).catch((err)=>{
          console.log(err);
        })
      },
      okbtn(){
        // console.log(this.$route.query.code);
        // const query = this.$qs.parse(location);
        // alert(location);
        // console.log(query);
        // var code = query.code;
        // this.code = query.code;
        let code = utils.getUrlKey('code')
        console.log(code);
        let postData = this.$qs.stringify({
          mobile: this.mobile,
          // code: code,
          openId: this.openId,
          customerCategory: 2,
        });
        this.$axios({
          method:'POST',
          url:'api/customer/bindMobile',
          data:postData
        }).then((res)=>{
          console.log(res.data.msg);
          if (res.data.ret == 1){
            this.winshow1 = true;
            this.msgtext = '绑定成功';
          } else {
            this.winshow = true;
            this.msgtext = res.data.msg;
          }
        }).catch((err)=>{
          console.log(err);
        })
      },
      //  弹框隐藏
      winnone(){
        this.winshow = false;
      },
      //  弹框下一步
      next() {
        this.winshow1 = false;
        this.$router.replace({
          path:'/carbank'
        });
      }
    },
  }
</script>

<style scoped>
  *{
    margin: 0;
    padding: 0;
  }
  .header {
    width: 100%;
    height: 2.4rem;
    text-align: center;
    background: #609FE0;
    z-index: 999;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
  }
  .header p {
    line-height: 2.4rem;
    font-size: 1.05rem;
    color: white;
    font-weight: bolder;
  }
  .goto {
    position: relative;
  }
  .goto img {
    width: 1.8rem;
    height: 1.8rem;
    position: absolute;
    top: 0.3rem;
    left: 0.15rem;
  }
  /* 内容 */
  .content {
    position: fixed;
    width: 100%;
    height: 100%;
    top: 0;
    background: white;
    text-align: center;
  }
  .annotation {
    margin-top: 3rem;
    font-size: 0.9rem;
    color: #888888;
  }
  .iptPhone {
    width: 80%;
    height: 2rem;
    color: #666666;
    margin-top: 1rem;
    border: 1px solid gainsboro;
    border-radius: 0.25rem;
    font-size: 0.9rem;
    padding-left: 0.6rem;
    outline:0;
  }
  .okbtn {
    width: 80%;
    height: 2rem;
    margin-top: 3rem;
    background: #609FE0;
    border-radius: 0.25rem;
    display: inline-block;
  }
  .okbtn p {
    color: white;
    line-height: 2rem;
    font-size: 0.9rem;
  }





  /*  提示框  */
  .winshow {
    position: fixed;
    width: 100%;
    height: 100%;
    top: 0;
  }
  .an {
    position: fixed;
    width: 100%;
    height: 100%;
    top: 0;
    background: black;
    opacity: 0.4;
  }
  .ming {
    width: 80%;
    height: 10rem;
    background: white;
    position: fixed;
    top: 30%;
    left: 10%;
    border-radius: 0.25rem;
  }
  .mingtext {
    text-align: center;
    height: 6.8rem;
  }
  .mingtext p {
    line-height: 6.8rem;
    /*padding-top: 1rem;*/
    font-size: 0.85rem;
    color: #666666;
  }
  .mingbtnbox {
    text-align: center;
    border-top: 1px solid gainsboro;
  }
  .mingbtn {
    width: 5rem;
    border: 1px solid gainsboro;
    border-radius: 0.25rem;
    margin-top: 0.6rem;
    /*margin-left: 6.8rem;*/
    display: inline-block;
  }
  .mingbtn p {
    line-height: 1.9rem;
    color: #666666;
    font-size: 0.88rem;
  }
  .imgbtn {
    border: 1px solid gainsboro;
    text-align: center;
    width: 5.5rem;
    border-radius: 0.25rem;
    display: inline-block;
    margin-top: 0.7rem;
  }
  .imgbtn p{
    line-height: 1.5rem;
    font-size: 0.85rem;
  }

</style>